package br.pucrio.inf.aaaong.models.domain.database.dao.basic;

import java.sql.SQLException;

import br.pucrio.inf.aaaong.models.database.exceptions.PostgreSQLConstraintException;
import br.pucrio.inf.aaaong.models.database.update.UpdateQueryExecutor;
import br.pucrio.inf.aaaong.models.database.update.UpdateQueryParamsPreparer;
import br.pucrio.inf.aaaong.models.database.update.UpdateQueryParamsSetter;
import br.pucrio.inf.aaaong.models.domain.database.dao.basic.beans.CandidatoBean;

public class CandidatoDAO {
	private static final String QUERY_INSERT = "insert into Candidato("
			+ "id_adolescente, numero_de_inscricao) "
			+ "values (?,?)";
	private UpdateQueryExecutor queryExecutor;

	public CandidatoDAO(UpdateQueryExecutor queryExecutor) {
		this.queryExecutor = queryExecutor;
	}

	public void insert(final CandidatoBean bean) throws PostgreSQLConstraintException {
		queryExecutor.execute(QUERY_INSERT, new UpdateQueryParamsPreparer() {
			
			@Override
			public void prepareParameters(UpdateQueryParamsSetter params) throws SQLException {
				params.setInt(bean.getId());
				params.setInt(bean.getNumeroDeInscricao());
			}
		});
	}
}